﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ShowroomMobile
{
    public partial class ManagerSlideShow : AdminBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ((AdminSite)Page.Master).SetTitlePage("Slide Show");
                gridSlides.Rebind();
            }
        }

        protected void gridSlides_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            if (e.CommandName == "DeleteAll")
            {
                //Delete all
                Showroom.BLL.SlideShow.DeleteAllSlides();
                gridSlides.CurrentPageIndex = 0;
                gridSlides.Rebind();
            }
            else if (e.CommandName == "Delete")
            {
                int ID = Convert.ToInt32(e.CommandArgument);
                Showroom.BLL.SlideShow.DeleteByID(ID);
                gridSlides.CurrentPageIndex = 0;
                gridSlides.Rebind();
            }
        }

        protected void gridSlides_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
        {
            gridSlides.CurrentPageIndex = e.NewPageIndex;
            gridSlides.Rebind();
        }

        protected void gridSlides_OnNeedDataSource(object sender, EventArgs e)
        {
            Showroom.BLL.SlideShow slides = new Showroom.BLL.SlideShow();
            int total = slides.Search("", "[ID] desc", gridSlides.CurrentPageIndex * gridSlides.PageSize, gridSlides.PageSize);
            gridSlides.VirtualItemCount = total;
            gridSlides.DataSource = slides.DefaultView;
        }

        protected void chkActive_OnCheckedChanged(object sender, EventArgs e)
        {
            CheckBox chk = (CheckBox)sender;
            int id = int.Parse(chk.Attributes["ItemID"].ToString());
            Showroom.BLL.SlideShow slides = new Showroom.BLL.SlideShow();
            slides.LoadByPrimaryKey(id);
            slides.Active = chk.Checked;
            slides.Save();

            gridSlides.Rebind();
        }

        protected void btnReloadGridSlides_Click(object sender, EventArgs e)
        {
            gridSlides.Rebind();
        }

    }
}